import '../scss/login.scss'
import React from 'react'
import {userApi} from '../api/user.js'

export default React.createClass({
    contextTypes: {
        router: React.PropTypes.object
    },
    register(e) {
        e.preventDefault()
        e.stopPropagation()
        var self = this
        var data = {
            password: this.refs.password.value,
            username: this.refs.username.value
        }
        userApi.userRegister(data, function() {
            self.context.router.push('/login')
        })
        return false
    },
    render() {
        return <div id='login'>
            <span className='g_title'>注册</span>
            <form onSubmit={this.register}>
                <div className='flex'>
                    <div className='flex-col-4'>用户名</div>
                    <div><input type='text' name='username' ref='username'/></div>
                </div>
                <div className='flex'>
                    <div className='flex-col-4'>密码</div>
                    <div><input type='text' name='password' ref='password'/>
                    </div>
                </div>
                <input type='submit' value='注册'/>
            </form>
        </div>
    }
})
